const Router = require('koa-router')
// const bcrypt = require('bcryptjs')
const {RegisterValidator} = require('../../validators/user')
const {handleResult} = require('../../lib/helper')
const {UserModel} = require('../../model/userModel')
const router = new Router({
  prefix: '/v1/user'
})

router.post('/register', async(ctx)=>{
  // console.log(ctx.request.body)
   const r = new RegisterValidator()
   const v = await r.validate(ctx)
  //  const salt = bcrypt.genSaltSync(4)
  //  const psw = bcrypt.hashSync(v.get('body.password2'), salt)
   const user = {
        email: v.get('body.email'),
        password: v.get('body.password2'),
        nickname: v.get('body.nickname')
    }

   const res = await UserModel.create(user)
   handleResult('晕死，你真的更新了吗')
})

module.exports = router;